<?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    function idFromUrl($href, $delimiter) {
        $href = urldecode($href);
        $ID = explode($delimiter, $href);
        $ID = $ID[count($ID) - 1];
        return $ID;
    }

    function url_name(&$data, $colum) {
        if (count($data) > 0)
            foreach ($data as $row)
                $row->url_name = URLify::filter($row->{$colum});
    }

    function url_name_single(&$data, $colum) {
        if (count($data) > 0)
            if (isset($data->seo_fix_url))
                $data->url_name = $data->seo_fix_url;
            else
                $data->url_name = URLify::filter($data->{$colum}) . '-' . (isset($data->ID)?$data->ID:$data->object_ID);
    }

    function url_cms_name(&$data, $colum) {
        if (count($data) > 0)
            foreach ($data as &$row)
                if (isset($row['seo_fix_url']))
                    $row['url_name'] = $row['seo_fix_url'];
                else if (isset($row[$colum]))
                    $row['url_name'] = URLify::filter($row[$colum]) . '-' . $row['ID'];
    }

    function url_cms_name_single(&$data, $colum) {
        if (count($data) > 0)
            if (isset($data[$colum]))
                $data['url_name'] = URLify::filter($data[$colum]);
    }

    function url_room_link(&$data, $x_get, $method = 'lang_url') {
        if (count($data) > 0)
            foreach ($data as &$row)
                if (count($row->rooms) > 0)
                    foreach ($row->rooms as &$room)
                        if ($method === 'lang_url')
                            $room->link = lang_url('accommodation/' . $row->url_name . '-' . $row->object_ID . '?' . $x_get . '&amp;room_id=' . $room->room_ID);
                        else
                            $room->link = base_url('accommodation/' . $row->url_name . '-' . $row->object_ID . '?' . $x_get . '&amp;room_id=' . $room->room_ID);
    }

    function url_room_link_hotel(&$data, $x_get, $method = 'lang_url') {
        if (count($data) > 0)
            foreach ($data as &$row)
                if (count($row->rooms) > 0)
                    foreach ($row->rooms as &$room):

                        $name = isset($row->seo_fix_url) && $row->seo_fix_url != '' ? $row->seo_fix_url : $row->url_name . '-' . $row->object_ID;

                        if ($method === 'lang_url')
                            $room->link = lang_url('montenegro-accommodation/' . $name . $x_get);
                        else
                            $room->link = base_url('montenegro-accommodation/' . $name . $x_get);


                    endforeach;
    }

    function url_room_link_single(&$data, $x_get, $method = 'lang_url') {

        if (count($data->rooms) > 0)
            foreach ($data->rooms as &$room)
                if ($method === 'lang_url')
                    $room->link = lang_url('accommodation/' . $data->url_name . '-' . $data->object_ID . '?' . $x_get . '&amp;room_id=' . $room->room_ID);
                else
                    $room->link = base_url('accommodation/' . $data->url_name . '-' . $data->object_ID . '?' . $x_get . '&amp;room_id=' . $room->room_ID);
    }
    